﻿using System;
using System.Windows.Input;

namespace SQ816FWUpdater
{
    // An ICommand implementation that takes a couple of delegates to 
    // implement Execute and CanExecute interfaces
    public class DelegateCommand : ICommand
    {
        public event EventHandler CanExecuteChanged;
        private Action Exec;
        private Func<bool> CanExec;
        public DelegateCommand(Action exec, Func<bool> canExec = null)
        {
            Exec = exec;
            CanExec = canExec;
        }
        public bool CanExecute(object parameter) { return (CanExec == null) ? true : CanExec(); }
        public void Execute(object parameter) { Exec(); }
        public void Notify()
        {
            var cec = CanExecuteChanged;
            if (cec != null)
                cec(this, new EventArgs());
        }
    }
}
